package wechat.base.snd;

import java.util.Collection;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.json.JSONArray;
import wechat.base.snd.WCApplication;
import wechat.base.snd.WCMPNewsItem;
import wechat.base.snd.WCMessage;
import wechat.base.snd.encoding.JsonPut;

@SuppressWarnings("all")
public class WCMPNews extends WCMessage {
  public WCMPNews(final WCApplication application) {
    super(application);
    this.encoding.setMsgType("mpnews");
  }
  
  private Collection<WCMPNewsItem> items = CollectionLiterals.<WCMPNewsItem>newArrayList();
  
  public WCMPNewsItem withItem(final String title) {
    WCMPNewsItem _wCMPNewsItem = new WCMPNewsItem(title);
    final Procedure1<WCMPNewsItem> _function = new Procedure1<WCMPNewsItem>() {
      public void apply(final WCMPNewsItem it) {
        WCMPNews.this.items.add(it);
      }
    };
    return ObjectExtensions.<WCMPNewsItem>operator_doubleArrow(_wCMPNewsItem, _function);
  }
  
  public void buildContents() {
    final JsonPut contents = new JsonPut();
    final JSONArray ja = new JSONArray();
    for (final WCMPNewsItem obj : this.items) {
      ja.put(obj.toJson());
    }
    final Procedure1<JsonPut> _function = new Procedure1<JsonPut>() {
      public void apply(final JsonPut it) {
        it.putObj("articles", ja);
      }
    };
    ObjectExtensions.<JsonPut>operator_doubleArrow(contents, _function);
    this.encoding.setMpNews(contents);
  }
}
